package cloud.xlh.my_system.controller;

import cloud.xlh.my_system.common.response.Response;
import cloud.xlh.my_system.pojo.PageRequest;
import cloud.xlh.my_system.pojo.ProjectForm;
import cloud.xlh.my_system.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : code-generator
 * @ Author: XuLeHuang
 * @ Date: 2022/6/1 12:48
 * @ Description:
 */
@Controller
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @RequestMapping("/toListPage")
    public String toListPage() {
        return "/project-manage/list";
    }

    @RequestMapping("/getListData")
    @ResponseBody
    public Response<HashMap> getListData(Integer limit , Integer page) {
        return projectService.getListData(limit , page);
    }

    @RequestMapping("/toAddPage")
    public String toAddPage() {
        return "/project-manage/add";
    }

    @PostMapping("/save")
    @ResponseBody
    public Response<Boolean> add(@RequestBody ProjectForm projectForm) {
        boolean save = projectService.save(projectForm);
        if(save){
            return Response.success("保存成功");
        }
        return Response.fail("保存失败");
    }

    @GetMapping("/option")
    @ResponseBody
    public Response<HashMap> option( PageRequest pageRequest) {
        return projectService.option(pageRequest);
    }
}
